<?php
namespace App\Models\Saas;

use App\Library\Tools;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Auth
 * @package app\saas\model
 * 设置表
 */
class UserManager extends Model
{
    protected $table = "saas_users"; //表名
    const CREATED_AT = null;
    const UPDATED_AT = null;

    public static function transferField($data){
        if(!$data){
            return [];
        }
        $data = Tools::transferFields($data);
        return $data;
    }

    public static function getList($field = '*', $filter = [], $page = 1, $limit = 10, $order = "create_time", $sort = "desc"){
        $db = self::query()->where($filter)->select(is_array($field) ? $field : explode(",", $field));
        $data['count'] = $db->count();
        $data['currentPage'] = $page;
        $data['totalPage'] = ceil(($data['count'])/$limit);
        $data['list'] = $db->skip(($page - 1) * $limit)->take($limit)->orderBy($order, $sort)->get();
        if($data['list']){
            $data['list'] = self::transferField($data['list']->toArray());
        }
        return $data;
    }
}